#!usr/bin/env python3
#该文件是启动程序
import logging
from app import create_app,db
from app.models import User,Role,selectAll,selectOne
from flask_script import Manager,Shell
from flask_migrate import Migrate,MigrateCommand
'''
logging.basicConfig(level=logging.DEBUG,  
                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',  
                    datefmt='%a, %d %b %Y %H:%M:%S',  
                    filename='weblogs.log',  
                    filemode='w')
'''

#http://127.0.0.1:5000/
app = create_app("df")
manage = Manager(app) #创建脚本管理
migrate = Migrate(app,db) #创建数据库迁移

def make_shell_context():
	return dict(app=app,db=db,User=User,Role=Role)

#添加单元测试命令,函数名就是shell命令
@manage.command 
def test():
	'''Run unittest '''
	import unittest
	discoverFolder = "test" #测试文件定义的路目录
	tests = unittest.TestLoader().discover(discoverFolder) 
	unittest.TextTestRunner(verbosity=2).run(tests)

manage.add_command("shell",Shell(make_context=make_shell_context))
manage.add_command("db",MigrateCommand) #创建数据库迁移命令

if __name__=="__main__":
	manage.run()